<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <ul>
        <!-- v-for用于做列表渲染，哪个元素要循环渲染就嫁给哪个元素 -->
        <!-- 有一个可选的第二个参数index -->
        <!-- for-in等价于for-of -->
        <li v-for="item of list">{{ item }}</li>
      </ul>

      <p v-for="({name}, index) in list2">{{ name }} - {{ index }}</p>

      <div v-for="value in list2">
        {{ value.name }} 喜欢
        <span v-for="item in value.likes">{{ item }}</span>
      </div>

      <!-- 对象循环也是用v-for指令，对象循环有三个参数 -->
      <ul>
        <li v-for="(value, key, index) in myObject">
          {{ value }} - {{ key }} - {{ index }}
        </li>
      </ul>

      <ul>
        <!-- 10相当于[1,2,3,4,5,6,7,8,9,10] -->
        <li v-for="n in 10">{{ n }}</li>
      </ul>

      <div v-for="value in 9">
        <span v-for="val in value">
          {{value}} * {{val}} = {{value * val}}
        </span>
      </div>

      <ul>
        <template v-for="item in list2">
          <li>{{ item.id }}</li>
          <li>{{ item.name }}</li>
        </template>
      </ul>
    </div>

    <script src="./Vue3.js"></script>
    <script>
      const { createApp } = Vue;

      createApp({
        data() {
          return {
            list: [1, 2, 3, 4],
            list2: [
              {
                id: 1,
                name: "zhangsan",
                likes: [299, 399, 699],
              },
              {
                id: 2,
                name: "lisi",
                likes: [699, 1299, 1599],
              },
            ],

            myObject: {
              title: "How to do lists in Vue",
              author: "Jane Doe",
              publishedAt: "2016-04-10",
            },
          };
        },
      }).mount("#app");
    </script>
  </body>
</html>
